package com.jdk.demo.reflect.clazz;

import java.lang.reflect.Field;
import java.util.Arrays;

public class EnumDemo {

	enum Color {
		RED, BLACK, BLUE
	}

	public static class ColorHolder {

		private Color color = Color.BLACK;

	}

	public static void main(String[] args) throws Exception {
		Class<Color> colorClass = Color.class;
		System.out.println("Color class is enum:" + colorClass.isEnum());
		System.out.println("Color values:" + Arrays.toString(colorClass.getEnumConstants()));
		ColorHolder colorHolder = new ColorHolder();
		Class<ColorHolder> holderClass = ColorHolder.class;
		Field field = holderClass.getDeclaredField("color");
		field.setAccessible(true);
		System.out.println("Old color:" + field.get(colorHolder));
		field.set(colorHolder, Color.RED);
		System.out.println("New color:" + field.get(colorHolder));
	}

}
